package timberman.screens;

import timberman.character.Man;
import timberman.core.AssetUtils;
import timberman.models.Tree;
import timberman.models.Wood;

import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

public class TestScreen extends AbstractScreen {
	Skin skin;
	public static final int NUMBER_WOOD = 9;
	Tree tree;
	Group groupChopedWood = new Group();
	Man man ;
	
	public TestScreen() {
		super();
		skin = AssetUtils.skin;
		tree = new Tree(NUMBER_WOOD);
		tree.setPosition((stage.getWidth() - tree.getWidth()) / 2, 200);
		groupChopedWood.setPosition(tree.getX(), tree.getY());
		stage.addActor(tree);
		man = new Man();
		System.out.println("number region " + man.getAnimation().getKeyFrames().length);
		stage.addActor(man);
		

	}

	public static TestScreen instance = null;

	public static TestScreen getInstance() {
		if (instance == null)
			instance = new TestScreen();
		return instance;
	}

	@Override
	public void doWhenBack() {

	}

	@Override
	public void doWhenHome() {

	}

	@Override
	public void acting() {

	}

	@Override
	public void doWhenTouch(int x, int y) {
		
		
		if (tree.chopable) {
			/**
			 * Man chuyen dung vi tri, thuc hien animation
			 */
			System.out.println("x = " + x);
			System.out.println("y = " + y);
			man.changePosition(x);
			man.setChop(true);
			
			
			
			final Wood w = tree.updateWhenChoped();
			w.setPosition(0, 0);
			groupChopedWood.addActor(w);

			stage.addActor(groupChopedWood);
			w.setOrigin(w.getWidth() / 2, w.getHeight() / 2);
			w.addAction(Actions.parallel(Actions.rotateBy(360f, 0.5f), Actions
					.sequence(Actions.moveBy(200, 100, 1f), new Action() {

						@Override
						public boolean act(float delta) {
							groupChopedWood.removeActor(w);
							return true;
						}
					})));

		}
	}

}
